package cn.topcodes.tcsf.admin.commons.api.controller.query;

import cn.topcodes.tcsf.admin.commons.api.domain.ApiResponseEntity;
import cn.topcodes.tcsf.admin.commons.domain.IdEntity;
import cn.topcodes.tcsf.admin.commons.domain.Page;
import cn.topcodes.tcsf.admin.commons.query.IQueryIdEntityService;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

public class QueryIdEntityApiController<T extends IdEntity, V>
		extends QueryApiController<T, V> implements QueryIdEntityApi<V> {
	
	@Autowired
	private IQueryIdEntityService<T> queryIdEntityService;

	@Override
	public ApiResponseEntity<List<V>> listMarkDelete(
			HttpServletRequest request
		) {
		Map<String,String[]> searchParams = request.getParameterMap();
		ApiResponseEntity<List<V>> apiResponse = ApiResponseEntity.buildOK();
		List<T> listT = this.queryIdEntityService.findAllMarkDelete(searchParams);
		List<V> listV = this.entity2Vo(listT,request);
		return apiResponse.setBody(listV);
	}

	@Override
	public ApiResponseEntity<Page<V>> pageListMarkDelete(
			HttpServletRequest request,
			@ApiParam(value="页号") @RequestParam(value="page",required=false,defaultValue="1") Integer pageNumber,
			@ApiParam(value="每页条数") @RequestParam(value="size",required=false,defaultValue="10") Integer pageSize
			) {
		Map<String,String[]> searchParams = request.getParameterMap();
		ApiResponseEntity<Page<V>> apiResponse = ApiResponseEntity.buildOK();
		Page<T> pageT = this.queryIdEntityService.findPageMarkDelete(searchParams, pageNumber, pageSize);
		Page<V> pageV = this.entity2Vo(pageT,request);
		return apiResponse.setBody(pageV);
	}

	@Override
	public ApiResponseEntity<List<V>> listEnable(
			HttpServletRequest request
		) {
		Map<String,String[]> searchParams = request.getParameterMap();
		ApiResponseEntity<List<V>> apiResponse = ApiResponseEntity.buildOK();
		List<T> listT = this.queryIdEntityService.findAllEnable(searchParams);
		List<V> listV = this.entity2Vo(listT,request);
		return apiResponse.setBody(listV);
	}

	@Override
	public ApiResponseEntity<Page<V>> pageListEnable(
			HttpServletRequest request,
			@ApiParam(value="页号") @RequestParam(value="page",required=false,defaultValue="1") Integer pageNumber,
			@ApiParam(value="每页条数") @RequestParam(value="size",required=false,defaultValue="10") Integer pageSize
			) {
		Map<String,String[]> searchParams = request.getParameterMap();
		ApiResponseEntity<Page<V>> apiResponse = ApiResponseEntity.buildOK();
		Page<T> pageT = this.queryIdEntityService.findPageEnable(searchParams, pageNumber, pageSize);
		Page<V> pageV = this.entity2Vo(pageT,request);
		return apiResponse.setBody(pageV);
	}

	@Override
	public ApiResponseEntity<List<V>> listDisable(
			HttpServletRequest request
		) {
		Map<String,String[]> searchParams = request.getParameterMap();
		ApiResponseEntity<List<V>> apiResponse = ApiResponseEntity.buildOK();
		List<T> listT = this.queryIdEntityService.findAllDisable(searchParams);
		List<V> listV = this.entity2Vo(listT,request);
		return apiResponse.setBody(listV);
	}

	@Override
	public ApiResponseEntity<Page<V>> pageListDisable(
			HttpServletRequest request,
			@ApiParam(value="页号") @RequestParam(value="page",required=false,defaultValue="1") Integer pageNumber,
			@ApiParam(value="每页条数") @RequestParam(value="size",required=false,defaultValue="10") Integer pageSize
			) {
		Map<String,String[]> searchParams = request.getParameterMap();
		ApiResponseEntity<Page<V>> apiResponse = ApiResponseEntity.buildOK();
		Page<T> pageT = this.queryIdEntityService.findPageDisable(searchParams, pageNumber, pageSize);
		Page<V> pageV = this.entity2Vo(pageT,request);
		return apiResponse.setBody(pageV);
	}

}
